Skip to content

temperature_measurement: add FindClusterOnEndpoint and SetMeasuredVal… - #1816

Open
dietolive-tw wants to merge 1 commit into
espressif:mainfrom
dietolive-tw:add-temp-find-cluster
Open

temperature_measurement: add FindClusterOnEndpoint and SetMeasuredVal…#1816
dietolive-tw wants to merge 1 commit into
espressif:mainfrom
dietolive-tw:add-temp-find-cluster

Conversation

@dietolive-tw

Copy link
Copy Markdown

temperature_measurement: add FindClusterOnEndpoint and SetMeasuredValue wrappers

The flow_measurement and relative_humidity_measurement integration.cpp files provide namespace-level FindClusterOnEndpoint() and SetMeasuredValue() wrappers so application code can write to codegen cluster storage directly (bypassing esp-matter attribute::update, which desyncs for non-writable attributes on codegen clusters — esp-matter storage vs codegen mMeasuredValue).

temperature_measurement was missing these wrappers. Add them following the flow_measurement pattern so apps using TemperatureMeasurement can use SetMeasuredValue() the same way.

Refs: pattern from clusters/flow_measurement/integration.cpp

Description

temperature_measurement was the only measurement cluster in
components/esp_matter/data_model_provider/clusters/ without
namespace-level FindClusterOnEndpoint() and SetMeasuredValue()
wrappers in its integration.cpp. flow_measurement and
relative_humidity_measurement already provide them.

For codegen-backed clusters, writing a non-writable attribute via
esp_matter::attribute::update() desyncs the two stores: it writes
the esp-matter storage, but ReadAttribute reads from the codegen
mMeasuredValue. Application code that wants to update
MeasuredValue must call the codegen SetMeasuredValue() method on
the cluster instance.

The cluster instance is looked up via FindClusterOnEndpoint(endpointId),
which exists in CodegenIntegration.h — but the matching
CodegenIntegration.cpp is excluded from the esp-matter build by
CMakeLists.txt (EXCLUDE_SRCS_LIST for Codegen*.cpp). The other
measurement clusters solve this by re-declaring the wrapper in
integration.cpp (the file actually compiled).

Without this wrapper, apps that call
TemperatureMeasurement::SetMeasuredValue() get a link error.

Changes

  • components/esp_matter/data_model_provider/clusters/temperature_measurement/integration.cpp
    • Add FindClusterOnEndpoint(EndpointId) (matches flow_measurement pattern)
    • Add SetMeasuredValue(EndpointId, DataModel::Nullable<int16_t>) convenience wrapper
namespace chip::app::Clusters::TemperatureMeasurement {

TemperatureMeasurementCluster * FindClusterOnEndpoint(EndpointId endpointId)
{
    auto it = gServers.find(endpointId);
    if (it == gServers.end() || !it->second.IsConstructed()) {
        return nullptr;
    }
    return &it->second.Cluster();
}

CHIP_ERROR SetMeasuredValue(EndpointId endpointId, DataModel::Nullable<int16_t> measuredValue)
{
    auto * cluster = FindClusterOnEndpoint(endpointId);
    VerifyOrReturnError(cluster != nullptr, CHIP_ERROR_NOT_FOUND);
    return cluster->SetMeasuredValue(measuredValue);
}

} // namespace chip::app::Clusters::TemperatureMeasurement

Related

  • Pattern source: components/esp_matter/data_model_provider/clusters/flow_measurement/integration.cpp
  • Pattern source: components/esp_matter/data_model_provider/clusters/relative_humidity_measurement/integration.cpp
  • Build exclusion: components/esp_matter/data_model_provider/CMakeLists.txt (EXCLUDE_SRCS_LIST for Codegen*.cpp)

Testing

  • Pattern matches existing flow_measurement/integration.cpp and
    relative_humidity_measurement/integration.cpp exactly — no behavior
    change for apps that do not call the new wrappers.
  • Build verified with an out-of-tree ESP-IDF + esp-matter example that calls
    TemperatureMeasurement::SetMeasuredValue(); without this wrapper the link
    step fails with an undefined reference to
    FindClusterOnEndpoint(EndpointId), with it the link succeeds and the
    attribute reads back the value set via the codegen path.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant

CLAassistant commented Aug 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

return &it->second.Cluster();
}

CHIP_ERROR SetMeasuredValue(EndpointId endpointId, DataModel::Nullable<int16_t> measuredValue)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this helper really needed? I mean the end user can call FindClusterOnEndpoint() and then call cluster->SetMeasuredValue().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd lean towards keeping it for consistency with the sibling measurement clusters. flow_measurement, relative_humidity_measurement, and pressure_measurement all expose this exact SetMeasuredValue(EndpointId, …) helper next to FindClusterOnEndpoint() — see flow_measurement/integration.cpp:50, relative_humidity_measurement/integration.cpp:50, pressure_measurement/integration.cpp:50.
Removing it here makes temperature_measurement the odd one out and pushes the nullptr → CHIP_ERROR_NOT_FOUND check into every caller. It's a one-line wrapper with no behavior change, so I'd keep the pattern uniform across the measurement clusters.

@dietolive-tw

dietolive-tw commented Aug 14, 2026

Copy link
Copy Markdown
Author

One thing missing before this can land: the PR only adds the symbols to integration.cpp, but all three sibling clusters ship a matching integration.h that publicly declares FindClusterOnEndpoint and SetMeasuredValue:

 - clusters/flow_measurement/integration.h
 - clusters/relative_humidity_measurement/integration.h
 - clusters/pressure_measurement/integration.h

Note: the upstream connectedhomeip/src/app/clusters/temperature-measurement-server/CodegenIntegration.h already declares these symbols, so app code already has a declaration available via that header — integration.h is not a blocker. The case for adding it is purely consistency with the sibling measurement clusters, which all ship a matching integration.h and #include "integration.h" first in their integration.cpp. Could you add temperature_measurement/integration.h mirroring flow_measurement/integration.h (just swap the type to TemperatureMeasurementCluster and the arg to Nullable<int16_t>)? Rest looks good to me.

…ue wrappers

The flow_measurement and relative_humidity_measurement integration.cpp files
provide namespace-level FindClusterOnEndpoint() and SetMeasuredValue() wrappers
so application code can write to codegen cluster storage directly (bypassing
esp-matter attribute::update, which desyncs for non-writable attributes on
codegen clusters — esp-matter storage vs codegen mMeasuredValue).

temperature_measurement was missing these wrappers. Add them following the
flow_measurement pattern so apps using TemperatureMeasurement can use
SetMeasuredValue() the same way.

Refs: pattern from clusters/flow_measurement/integration.cpp
@dietolive-tw
dietolive-tw force-pushed the add-temp-find-cluster branch from 6803bff to 3abe4c2 Compare August 14, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants